package edu.whut.jdk8.localClass;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/*
Instant类
 */
public class InstantDemo {
    public static void main(String[] args) {
        //当前时间（默认时区）
        Instant now = Instant.now();
        System.out.println(now);

        //根据毫秒、秒获取Instant对象
        Instant instant1 = Instant.ofEpochMilli(1000);
        Instant instant2 = Instant.ofEpochSecond(5);
        System.out.println(instant1);
        System.out.println(instant2);

        //指定时区的Instant对象
        ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneId.systemDefault());
        System.out.println(zonedDateTime);

        //判断相关的方法
        System.out.println(now.isBefore(instant1));
        System.out.println(instant1.isAfter(instant1));

        //减少、增加时间的方法
        System.out.println(now.minusMillis(1000));
        System.out.println(now.minusSeconds(5));
        System.out.println(now.plusMillis(2000));
        System.out.println(now.plusSeconds(5));
    }
}
